/*
* created by Administrator on 2018/11/28
* 好的代码像粥一样,是得用时间和精力熬的。
*/
//ECMAscript 2015 [ES6]
// function log(n) {
//    return n;
// }
// let log = n => n;
// const a = 1;
// 定义变量 【let const】
// let 代替var 它能够形成（块级）作用域
let a = 1;
let b = 2;
// console.log(a + b);
for (let i = 0;i < 10;i++){
    // console.log(i);
}
for (let i = 0;i < 11;i++){}
//const 定义的变量[常量]不能被重新赋值 但是可修改
const  c= 11;
// c = 123;
const o = {
    c:11
};
o.c = 123;
// console.log(o);

//字符串
// 模板字符串
// console.log("还有" + b + "天就放假！");
// console.log(`还有${b}天就放假！`);
let str = `还有${b}天就放假！`;
// for of 循环
for (var i of str){
    // console.log(i);
}
// 方法
// function detect(str, char) {
//     return str.indexOf(char) > -1;
// }
// console.log(detect('hello','x'));
// console.log('hello'.includes('h'));
// console.log('a'.repeat(5));
//解构赋值 【解析解构对应赋值】 一一对应的赋值
let [a1 , a2,a3 , a4,a5 , a6,a7 , a8,a9] = str;
// console.log(a1);
// console.log(a3);
// console.log(a8);
// console.log(a9);
// 数组 new Array
// 静态方法 Array.form 把类数组【arrayLike】 转化 数组【array】
// 扩展运算符 ...
// 解构复制
function toArray (arrayLike){
    return [].slice.call(arrayLike,0);
}
(function () {
   // console.log(arguments);
   // console.log(Array.from(arguments));
})(1,2,3,434,35,458);

let arr2 = [1,2,34,5,true,function () {}];
let arr3 = ['hello,world!',...arr2,'abc'];
console.log(arr3);
// let arr4 = arr2;//不是复制
let arr4 = [...arr2];//是复制
arr2.push(123);
console.log(arr4);
function clone(obj){
    // return JSON.stringify(obj);
    return JSON.parse(JSON.stringify(obj));
}
let [g,h, j] = arr2;
console.log(g);//1
console.log(h);//2
console.log(j);//34

//对象
// var name1 = 'wanghong';
// var age = 16;
// var o2 = {
//     name:name,
//     age:age,
//     coding:function(){
//         console.log('coding!!');
//     }
// };
let name = 'wanghong';
let age = 16;
let o3 = {a, b};
let o2 = {
    name,
    age,
    coding(){
        console.log('coding。');
    },
    ...o3,
};
console.log(o2);

let foo = {
    w:123,
    q:456
};
let{q,w} = foo;
console.log(q);
console.log(w);

console.log('1234'.split(''));
console.log([...'1234']);
let numArr = [12,32823,233,98,8,238,19,38,276,198,28];
// console.log(Math.max.apply(null,[1,21,32,1,2]));
console.log(Math.max(...numArr));
//箭头函数
//this
// function bar1() {
//    console.log(this);
// }
// let bar2 = () => {
//     console.log(this);
// };
// bar1.call(foo);
// bar2.call(foo);
function bar1() {
    let bar2 = () => {
        console.log(this);
    };
   console.log(this);
   bar2();
}
bar1.call(foo);

//如果函数体只有1行代码 默认return {}可省略
let fn1 = () => 3;
let fn2 = n => n;//一个参数情况下（）可不写
let fn3 = (m,n) =>  m+n;
console.log(fn1());
console.log(fn2(10));
console.log(fn3(10,10));

// function sum() {
//     var res = 0;
//     for(var i = 0;i<arguments.length;i++){
//         res += arguments[i];
//     }
//     return res;
// }
// let sum = (...arg) =>{
//   // console.log(arg);
//     let res = 0;
//     arg.forEach((v) => res += v);
//     return res;
// };
let sum = (...arg) => arg.reduce(((previousValue,currentValue) => previousValue + currentValue),0);
function sum1(){
    return [].splice.call(arguments,0).reduce(function (previousValue,currentValue) {
       return previousValue + currentValue ;
    },0);
}
sum1(1,3,321,12,34,65,8,45,6,3432,76576);
console.log(sum(1,3,321,12,34,65,8,45,6,3432,76576));


function add(m,n) {
    return m ||0+ n||0;
}

console.log(add());

let add1 = (m=0,n=0) => m + n;
console.log(add1(12,9));
